package com.jdy.haoduoaiteacher.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.jdy.haoduoaiteacher.model.ImageItem;
import com.jdy.haoduoaiteacher.util.Tools;
import com.jdy.haoduoaiteacher.view.AspectRatioImageView;
import com.squareup.picasso.Picasso;
import com.ycsj.goldmedalnewconcept.R;

import java.util.List;

public class ImageListAdapter extends BaseAdapter {
  private Context mContext;
  private List<ImageItem> mDataList;
  private boolean isEditable;

  public void setEditable(boolean isEditable) {
    this.isEditable = isEditable;
  }

  public ImageListAdapter(Context context, List<ImageItem> dataList) {
    this.mContext = context;
    this.mDataList = dataList;
  }

  @Override
  public int getCount() {
    return mDataList == null ? 0 : mDataList.size();
  }

  @Override
  public Object getItem(int position) {
    return mDataList.get(position);
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder mHolder;

    if (convertView == null) {
      convertView = View.inflate(mContext, R.layout.item_image_list2, null);
      mHolder = new ViewHolder();
      mHolder.imageIv = (AspectRatioImageView) convertView
          .findViewById(R.id.image);
      // mHolder.selectedIv = (ImageView) convertView
      // .findViewById(R.id.selected_tag);
      // mHolder.selectedBgTv = (TextView) convertView
      // .findViewById(R.id.image_selected_bg);
      convertView.setTag(mHolder);
    } else {
      mHolder = (ViewHolder) convertView.getTag();
    }

    final ImageItem item = mDataList.get(position);

    // ImageDisplayer.getInstance(mContext).displayBmp(mHolder.imageIv,
    // item.thumbnailPath, item.sourcePath);

      if (Tools.isNotEmpty(item.url)) {
          Picasso.with(mContext).load(item.url).into(mHolder.imageIv);
      }

    // if (item.isSelected) {
    // mHolder.selectedIv.setImageDrawable(mContext.getResources().getDrawable(
    // R.drawable.tag_selected));
    // // mHolder.selectedIv.setVisibility(View.VISIBLE);
    // // mHolder.selectedBgTv.setBackgroundResource(R.drawable.image_selected);
    // } else {
    // mHolder.selectedIv.setImageDrawable(mContext.getResources().getDrawable(
    // R.drawable.tag_unselected));
    // // mHolder.selectedIv.setVisibility(View);
    // // mHolder.selectedBgTv.setBackgroundResource(R.color.light_gray);
    // }

    // if (isEditable) {
    // mHolder.selectedIv.setVisibility(View.VISIBLE);
    // } else {
    // mHolder.selectedIv.setVisibility(View.GONE);
    // }

    return convertView;
  }

  static class ViewHolder {
    private AspectRatioImageView imageIv;
    // private ImageView selectedIv;
    // private TextView selectedBgTv;
  }

}
